package cn.iocoder.yudao.module.enterprise.controller.admin.curriculumVitaeSendRecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.SortingField;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.member.api.curriculumVitaeSendRecord.CurriculumVitaeSendRecordApi;
import cn.iocoder.yudao.module.member.api.curriculumVitaeSendRecord.dto.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 -企业端- 简历投递记录")
@RestController
@RequestMapping("/enterprise/curriculum-vitae-send-record")
@Validated
public class EnterpriseCurriculumVitaeSendRecordController {

    @Resource
    private CurriculumVitaeSendRecordApi curriculumVitaeSendRecordApi;

//    @PostMapping("/create")
//    @ApiOperation("创建简历投递记录")
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:create')")
//    public CommonResult<Long> createCurriculumVitaeSendRecord(@Valid CurriculumVitaeSendRecordCreateReqVO createReqVO) {
//        return success(curriculumVitaeSendRecordService.createCurriculumVitaeSendRecord(createReqVO));
//    }
//
//    @PutMapping("/update")
//    @ApiOperation("更新简历投递记录")
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:update')")
//    public CommonResult<Boolean> updateCurriculumVitaeSendRecord(@Valid CurriculumVitaeSendRecordUpdateReqVO updateReqVO) {
//        curriculumVitaeSendRecordService.updateCurriculumVitaeSendRecord(updateReqVO);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete")
//    @ApiOperation("删除简历投递记录")
//    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:delete')")
//    public CommonResult<Boolean> deleteCurriculumVitaeSendRecord(@RequestParam("id") Long id) {
//        curriculumVitaeSendRecordService.deleteCurriculumVitaeSendRecord(id);
//        return success(true);
//    }
//
    @GetMapping("/get")
    @ApiOperation("获得简历投递记录")
    public CommonResult<CurriculumVitaeSendRecordRespDTO> getCurriculumVitaeSendRecord(@RequestParam("id") Long id) {
        CurriculumVitaeSendRecordRespDTO curriculumVitaeSendRecord = curriculumVitaeSendRecordApi.getCurriculumVitaeSend(id,true);
        return success(curriculumVitaeSendRecord);
    }
//
//    @GetMapping("/list")
//    @ApiOperation("获得简历投递记录列表")
//    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:query')")
//    public CommonResult<List<CurriculumVitaeSendRecordRespVO>> getCurriculumVitaeSendRecordList(@RequestParam("ids") Collection<Long> ids) {
//        List<CurriculumVitaeSendRecordDO> list = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordList(ids);
//        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertList(list));
//    }
//
//    @GetMapping("/page")
//    @ApiOperation("获得简历投递记录分页")
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:query')")
//    public CommonResult<PageResult<CurriculumVitaeSendRecordRespVO>> checkResumeFromJob(@Valid CurriculumVitaeSendRecordPageReqVO pageVO) throws Exception{
//        PageResult<CurriculumVitaeSendRecordDO> pageResult = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordPage(pageVO);
//        return success(CurriculumVitaeSendRecordConvert.INSTANCE.convertPage(pageResult));
//    }

//    @GetMapping("/admin/checkResumeFromJob")
//    @ApiOperation("获得简历投递记录分页")
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:query')")
//    public CommonResult<PageResult<CurriculumVitaeSendRecordRespVO>> getCurriculumVitaeSendRecordPage(@Valid CurriculumVitaeSendRecordPageReqVO pageVO) throws Exception{
//        return this.getCurriculumVitaeSendRecordPage(pageVO);
//
//    }
//
//
//    @GetMapping("/export-excel")
//    @ApiOperation("导出简历投递记录 Excel")
//    @PreAuthorize("@ss.hasPermission('member:curriculum-vitae-send-record:export')")
//    @OperateLog(type = EXPORT)
//    public void exportCurriculumVitaeSendRecordExcel(@Valid CurriculumVitaeSendRecordExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<CurriculumVitaeSendRecordDO> list = curriculumVitaeSendRecordService.getCurriculumVitaeSendRecordList(exportReqVO);
//        // 导出 Excel
//        List<CurriculumVitaeSendRecordExcelVO> datas = CurriculumVitaeSendRecordConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "简历投递记录.xls", "数据", CurriculumVitaeSendRecordExcelVO.class, datas);
//    }


    @PostMapping("/checkInfoByJob")
    @ApiOperation("根据职位获得简历投递记录分页")
    public CommonResult<PageResult<CurriculumVitaeSendRecordGroupRespDTO>> checkInfoByJob(@Valid @RequestBody CurriculumVitaeSendRecordGroupPageReqDTO pageVO) {
        PageResult<CurriculumVitaeSendRecordGroupRespDTO> pageResult = curriculumVitaeSendRecordApi.checkInfoByJob(pageVO);
        return success(pageResult);
    }

    @PostMapping("/getpageByJob")
    @ApiOperation("各职位投递列表")
    public CommonResult<PageResult<CurriculumVitaeSendRecordRespDTO>> getpageByJob(@Valid @RequestBody CurriculumVitaeSendRecordPageReqDTO pageVO) {
//        PageResult<CurriculumVitaeSendRecordRespDTO> pageResult = curriculumVitaeSendRecordApi.getpageByJob(pageVO);
        pageVO.setRelationType(3);
        if(  null==pageVO.getSortField()){
            SortingField sf=new SortingField();
            sf.setField("j.updateTime");
            sf.setOrder("desc");
            pageVO.setSortField(sf);
        }
        PageResult<CurriculumVitaeSendRecordRespDTO> pageResult = curriculumVitaeSendRecordApi.getCurriculumVitaeSendRecordPage(pageVO);
        return success(pageResult);
    }


    @PostMapping("/saveEnterpriseCollect")
    @ApiOperation("企业端-收藏/取消收藏")
    @PreAuthenticated
    public CommonResult<Long> saveEnterpriseCollect(@Valid @RequestBody CollectNotesDTO createReqVO) {
        return success(curriculumVitaeSendRecordApi.createCollectNotes(createReqVO));
    }
    @PostMapping("/saveEnterpriseNotes")
    @ApiOperation("企业端-添加备注")
    @PreAuthenticated
    public CommonResult<Long> saveEnterpriseNotes(@Valid @RequestBody CollectNotesDTO createReqVO) {
        if(StringUtils.isBlank(createReqVO.getRemarks())){
            return error("备注信息不能为空");
        }
        return success(curriculumVitaeSendRecordApi.createCollectNotes(createReqVO));
    }


    @PostMapping("/getEnterpriseNotesPage")
    @ApiOperation("企业端-历史备注")
    @PreAuthenticated
    public CommonResult<PageResult<CollectNotesRespDTO>> getEnterpriseNotesPage(@Valid @RequestBody CollectNotesPageReqDTO pageVO) {
        if(  null==pageVO.getSortField()){
            SortingField sf=new SortingField();
            sf.setField("n.update_time");
            sf.setOrder("desc");
            pageVO.setSortField(sf);
        }
        PageResult<CollectNotesRespDTO> pageResult = curriculumVitaeSendRecordApi.getCollectNotesPage(pageVO);
        return success(pageResult);
    }
}
